package top.songxs.gmall.cart.rpc;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.songxs.gmall.cart.biz.CartRpcService;
import top.songxs.gmall.cart.entity.CartItem;
import top.songxs.gmall.cart.vo.AddCartSuccessVo;
import top.songxs.gmall.common.result.Result;
import top.songxs.gmall.common.result.ResultCodeEnum;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("api/inner/cart")
public class CartRpcController {

    @Autowired
    private CartRpcService cartRpcService;

    @GetMapping(value = "/addCart/{skuId}/{skuNum}")
    public Result<AddCartSuccessVo> addCart(@PathVariable(value = "skuId") Long skuId,
                                            @PathVariable(value = "skuNum") Integer skuNum) {
        log.info("添加购物车数据,skuId:{} , skuNum:{}", skuId, skuNum);
        // TODO调用service完成购物车添加操作

        AddCartSuccessVo addCartSuccessVo = cartRpcService.addCart(skuId, skuNum);

        return Result.build(addCartSuccessVo, ResultCodeEnum.SUCCESS);

    }

    @DeleteMapping(value = "/deleteChecked")
    public Result deleteChecked() {

        cartRpcService.deleteChecked();

        return Result.ok();
    }

    @GetMapping(value = "/findAllCheckedCartItem")
    public Result<List<CartItem>> findAllCheckedCartItem() {
        List<CartItem> cartItemList = cartRpcService.findAllCheckedCartItem();
        return Result.ok(cartItemList) ;
    }


}
